//
//  Lib.h
//  MHO
//
//  Created by papo on 2/17/14.
//  Copyright (c) 2014 maihoang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Contants.h"
#import "SBJson.h"
#import "DownloadManager.h"
#import "ServiceLib.h"
#import "UIAlertView+Blocks.h"
#import "UIImageView+WebCache.h"
//#import 

static inline NSString* strCheckNull(NSString* str) {
    if (!str || ![str isKindOfClass:[NSString class]] || str.length <= 0 || [str isKindOfClass:[NSNull class]]) {
        return @"";
    }
    return str;
}

static inline id numberCheckNull(id num) {
    if (!num || [num isKindOfClass:[NSNull class]]) {
        return @(0);
    }
    if ([num isKindOfClass:[NSString class]] && [num length] <= 0) {
        return @(0);
    }
    return num;
}

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)


#define UIColorFromRGBA(rgbValue,alphaValue)  [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]

/** Get UIColor from RGB value
 example: UIColorFromRGB(0XFF0000);
 */
#define UIColorFromRGB(rgbValue)    UIColorFromRGBA(rgbValue,1.0)

@interface Lib : NSObject

+ (BOOL)isUserLogin;
+ (void)setUserLogin:(BOOL)login;
+ (void)showLoadingView;
+ (void)removeLoadingView;
+ (NSString*)getServiceId;
+ (NSString*)getServiceKey;
+ (BOOL)isIos7;

+ (void)showMessage:(NSString*)message title:(NSString*)title;

+ (void)setString:(NSString*)string forKey:(NSString*)key;
+ (NSString*)stringForKey:(NSString*)key;
+ (CGFloat)textViewHeightForAttributedText:(NSAttributedString *)text andWidth:(CGFloat)width;
+ (CGSize)text:(NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size;

+ (NSString*)getDocumentPath;

/** get UIColor from hex string
 first character must be #
 example: [Lib colorFromHexString:@"#FF0000" alpha:1.0];
 */
+ (UIColor*)colorFromHexString:(NSString*)color alpha:(CGFloat)alpha;

+ (UIColor*)colorFromHexString:(NSString *)color;

+ (void)shareFacebook:(NSString*)content;

+ (UIViewController*)getRootViewController;

+ (void)checkUpdate;

+ (void)installApp:(TCBlobDownloader*)downloader;

+ (unsigned long long)sizeOfFolder:(NSString*)folder;
+ (unsigned long long)sizeOfFile:(NSString*)file;

+ (NSString *) md5:(NSString *) input;

+ (void)getWANIPAddressWithCompletion:(void(^)(NSString *IPAddress))completion;
@end
